#include "item.h"
#include <QDebug>

Item::Item(const QString & t1, const QString & t2, QObject *parent) :
  QObject(parent),
  m_text1(t1),
  m_text2(t2),
  m_isOpen(false)
{}

QString Item::text1() const{
	return m_text1;
}

QString Item::text2() const{
	return m_text2;
}

void Item::setText1(const QString & text1){
	if(m_text1 != text1){
		m_text1 = text1;
		emit text1Change();
	}
}

void Item::setText2(const QString & text2){
	if(m_text2 != text2){
		m_text2 = text2;
		emit text2Change();
	}
}

QList<QObject *> Item::childItems() const{
	return m_childItems;
}

void Item::addChild(Item * child){
	if(child->parent() != this)
		child->setParent(this);
	
	m_childItems << child;
	
	if(m_childItems.size() == 1)
		emit hasChildChange();
}

bool Item::hasChild() const{
	return m_childItems.size() > 0;
}

bool Item::isOpen() const{
	return hasChild() ? m_isOpen : false;
}

void Item::setOpen(bool open){
	if(m_isOpen != open){
		m_isOpen = open;
		emit isOpenChange();
	}
}
